package com.cdtu.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.cdtu.entity.Notice;
import com.cdtu.mapper.ResourceMapper;
import com.cdtu.service.NoticeService;
import com.cdtu.mapper.NoticeMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
* @author Sakura
* @description 针对表【notice】的数据库操作Service实现
* @createDate 2023-01-08 20:53:16
*/
@Service
public class NoticeServiceImpl extends ServiceImpl<NoticeMapper, Notice>
    implements NoticeService{
    @Autowired
    private NoticeMapper noticeMapper;
    //查询所有公告
    @Override
    public List<Notice> queryAll() {
        return null;
    }

    @Override
    public List<Notice> selectRollingByPage(Integer startIndex, Integer pageSize, String title, Integer priority) {
        int start=(startIndex-1)*pageSize;
        List<Notice> noticeList=noticeMapper.selectRollingByPage(start,pageSize,title,priority);
        return noticeList;
    }

    //    根据条件分页查询公告
    @Override
    public List<Notice> selectByPage(Integer startIndex, Integer pageSize, String title) {
        int start=(startIndex-1)*pageSize;
        List<Notice> noticeList=noticeMapper.selectByPage(start,pageSize,title);
        return noticeList;
    }

    //查询公告总数
    @Override
    public int findTotal() {
        System.out.println(noticeMapper.findTotal());
        return noticeMapper.findTotal(); }

    @Override
    public int findUnRollingTotal() { return noticeMapper.findUnRollingTotal(); }
    @Override
    public int findUnRollingByNameTotal(String title) { return noticeMapper.findUnRollingByNameTotal(title); }

    @Override
    public int findByNameTotal(String title) { return noticeMapper.findByNameTotal(title); }

    //    查询正在滚动的公告数量
    @Override
    public int queryRollingLength() {
        return noticeMapper.queryRollingLength();
    }
//根据id来更新公告的状态
    @Override
    public boolean updateById(long id, Integer priority) {
        int result = noticeMapper.updateById(id,priority);
        if (result==1){
            return true;
        }else {
            return false;
        }
    }
//根据id删除公告
    @Override
    public boolean deleteByID(Long id) {
        int result=noticeMapper.deleteByID(id);
        if (result==1) return true;
        else return false;
    }
//新增公告
    @Override
    public boolean insertNewNotice(Notice notice) {
        int result = noticeMapper.insertNewNotice(notice);
        if (result==1) return true;
        else return false;
    }
//通过id来查询公告信息
    @Override
    public Notice selectById(Long id) {
        return noticeMapper.selectById(id);
    }
//根据条件对公告信息进行修改
    @Override
    public boolean updateByCondition(Notice notice) {
        int result=noticeMapper.updateByCondition(notice);
        if (result==1) return true;
        else return false;
    }
//根据公告的状态进行查询
    @Override
    public List<Notice> selectByPriority() {
        List<Notice> noticeList=noticeMapper.selectByPriority();
        return noticeList;
    }

}




